package com.cskaoyan.thread02.model.edition2;

import java.util.Random;

/*
     不停的做包子
 */
public class ProducerTask implements Runnable {

    Container container;

    // 表示包子的菜单
    Food[] foodBill = {new Food("杭州小笼包", 1), new Food("狗不理", 50),
            new Food("蟹黄包", 10), new Food("奶黄包", 3)};

    Random random;

    public ProducerTask(Container container) {
        this.container = container;

        random = new Random();
    }

    @Override
    public void run() {

        while (true) {
            // 做包子放入蒸笼
            int randomIndex = random.nextInt(foodBill.length);
            // 在生产者线程中，调用setFood
            container.setFood(foodBill[randomIndex]);
        }

    }
}
